package com.itheima.health.controller.admin;

import com.itheima.health.annotation.MyAnno;
import com.itheima.health.common.MessageConst;
import com.itheima.health.entity.Result;
import com.itheima.health.pojo.OrderSetting;
import com.itheima.health.service.OrdersettingService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * 预约设置
 */
@RestController
@Slf4j
@RequestMapping("/ordersetting")
public class OrdersettingController {

    @Autowired
    private OrdersettingService ordersettingService;

    /**
     * 根据月份查询
     *
     * @param year
     * @param month
     * @return
     */
    @GetMapping("/getOrderSettingByMonth")
    @MyAnno(empower = "GETORDERSETTINGBYMONTH")
    public Result getOrderSettingByMonth(@RequestParam("year") Integer year, @RequestParam("month") Integer month) {
        log.info("[预约设置-根据月份查询]data:{},getOrderSettingByMonth:{}", year, month);
        return ordersettingService.getOrderSettingByMonth(year, month);
    }

    /**
     * ⽂件上传批量
     *
     * @param file
     * @return
     */
    @PostMapping("/upload")
    @MyAnno(empower = "ORDERSETTING_UPLOAD")
    public Result upload(@RequestParam("excelFile") MultipartFile file) throws IOException {
        log.info("[预约设置-⽂件上传批量]data:{},upload:{}", file);
        return ordersettingService.upload(file);
    }

    /**
     *06_预约管理可预约单独设置
     * @param orderSetting
     * @return
     */
    @MyAnno(empower = "ORDERSETTING")
    @PostMapping("/editNumberByDate")
    public Result editNumberByDate(@RequestBody OrderSetting orderSetting) {
        try {
            ordersettingService.editNumberByDate(orderSetting);
            //预约设置成功
            return new Result(true, MessageConst.ORDERSETTING_SUCCESS);

        }catch (Exception e){
            e.printStackTrace();
            //预约设置失败
            return new Result(false, MessageConst.ORDERSETTING_FAIL);

        }
    }
}
